package com.acvoli.shopping.listener;

import com.acvoli.shopping.service.OrderService;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
public class KafkaLister {

    @Autowired
    private OrderService orderService;

    @KafkaListener(topics = "test")
    public void listen(ConsumerRecord<String, String> cr) throws Exception {

        System.out.println("Consumer----------------Consumer");
        String[] values = cr.value().split("_");
        String memberId = values[0];
        String skuId = values[1];
        String sum = values[2];

        orderService.commitNormalOrder(memberId, skuId, Integer.valueOf(sum));
    }
}
